package com.testitems.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 允许放行的url
 **/
@Getter
@AllArgsConstructor
public enum UrlPermitAllEnum {

    login("/api/login"),
    refreshToken("/api/refresh-token"),
    druid("/druid/**"),
    actuator("/actuator/**"),
    check("/api/check/"),
    messengerClient("/api/messenger/**"),
    icClient("/api/ic/**"),
    plugin("/api/plugin/**/**");
    private String url;

    static List<String> list = new ArrayList();

    public static List<String> getUrlList() {
        return list;
    }

    static {
        for (UrlPermitAllEnum e : UrlPermitAllEnum.values()) {
            list.add(e.url);
        }
    }

    public static boolean containUrl(String value) {
        final String url = list.stream().filter(item -> value.contains(item)).findFirst().orElse(null);
        if (StringUtils.isNotBlank(url)) {
            return true;
        }
        return false;
    }
}
